﻿using System;
using System.ComponentModel.Design;
using System.Runtime.InteropServices;
using EnvDTE;
using EnvDTE80;
using Microsoft.VisualStudio.Shell;

namespace KindOfMagic
{
  [Guid(Guids.guidKindOfMagicPkgString)]
  [PackageRegistration(UseManagedResourcesOnly = true)]
  [InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)]
  [ProvideMenuResource("Menus.ctmenu", 1)]
  [ProvideAutoLoad("{f1536ef8-92ec-443c-9ed7-fdadf150da82}")]
  public sealed class KindOfMagicPackage : Package
  {
    Wizard _wizard;

    protected override void Initialize()
    {
      base.Initialize();

      var dte = (DTE2)GetService(typeof(DTE));
      _wizard = new Wizard(dte);

      var mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
      if (mcs != null)
      {
        // Create the command for the menu item.
        {
          var menuCommandID = new CommandID(Guids.guidKindOfMagicCmdSet, (int)PkgCmdIDList.cmdidTurnKindOfMagicOff);
          var enable = new OleMenuCommand((s, e) => _wizard.ApplyKindOfMagic(CommandAction.Enable), menuCommandID);
          enable.BeforeQueryStatus += (s, e) => _wizard.UpdateCommand(enable, CommandAction.Enable);
          mcs.AddCommand(enable);
        }
        {
          var menuCommandID = new CommandID(Guids.guidKindOfMagicCmdSet, (int)PkgCmdIDList.cmdidTurnKindOfMagicOn);
          var disable = new OleMenuCommand((s, e) => _wizard.ApplyKindOfMagic(CommandAction.Disable), menuCommandID);
          disable.BeforeQueryStatus += (s, e) => _wizard.UpdateCommand(disable, CommandAction.Disable);
          mcs.AddCommand(disable);
        }
      }
    }
  }
}
